In [3]:
import pandas as pd
Show me the first lines of the original file
In [14]:
df = pd.read_excel('/tmp/gonzalo_test/aseg.xls')
df.head()
Out[14]:
Show me the region names containing 'Vent' or 'WM' or 'Hippo'
In [26]:
names = set([each for each in df['StructName'].tolist() \
if 'WM' in each
or 'Vent' in each
or 'Hippo' in each])
names
Out[26]:
Reshape the table and show me the first lines
In [27]:
df = pd.DataFrame(df[df['StructName'].isin(names)], columns=['subject', 'StructName', 'Volume_mm3'])
df = df.pivot(index='subject', columns='StructName', values='Volume_mm3')
df.head()
Out[27]:
Save it and success !
In [28]:
df.to_excel('/tmp/gonzalo_test/aseg_pivot.xls')
In [25]:
from IPython.display import Image
Image(url='http://s2.quickmeme.com/img/c3/c37a6cc5f88867e5387b8787aaf67afc350b3f37f357ed0a3088241488063bce.jpg')
Out[25]:
In [ ]: